#include <dbg.h>
#include <gtest/gtest.h>

#include <vector>

using std::vector;

class Solution {
public:
    static int maxArea(const vector<int>& height) {
        int res = 0;
        int left = 0;
        int right = static_cast<int>(height.size()) - 1;
        while (left < right) {
            if (height[left] < height[right]) {
                res = std::max(res, (right - left) * height[left]);
                ++left;
            } else {
                res = std::max(res, (right - left) * height[right]);
                --right;
            }
            dbg(res, left, right, " ");
        }
        return res;
    }
};

TEST(TEST1, maxArea) {
    Solution s;
    const vector height{1, 8, 6, 2, 5, 4, 8, 3, 7};
    EXPECT_EQ(s.maxArea(height), 49);
}

TEST(TEST2, maxArea) {
    Solution s;
    const vector height{1, 1};
    EXPECT_EQ(s.maxArea(height), 1);
}

int main(int argc, char** argv) {
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}